

cd "W:\Drive partagés\Bolno\Chat GPT paper\stata\data"

/******************************************************************************/
/*                              Program                                       */
/******************************************************************************/


capture program drop mygraph3_en
program define mygraph3_en
    syntax , [ytitre(string) q(integer 1) jit(integer 3) noLEGend TLow(string)  ///
        TUp(string) LABPos(real -0.1) LABSize(real .9) med *]
        
        
    if "`med'" != "" {
        local stat med
    }
    else {
        local stat m
    }
    if "`legend'" != "" { 
        local leg legend(off)
    }
    else {
        local leg legend(pos(6) row(1)  size(*.9) region(lcol(black))           ///
            order(4 "Experts" 5 "ChatGPT" 6 "Mistral AI") )
    }
    tempvar cap_up cap_low
    gen `cap_up'  = m`q' + s`q' 
    gen `cap_low' = m`q' - s`q' 
    local c1 black
    local c2 gs6
    local c3 gs10
    local lab0 mlabel(m`q') mlabf("%5,1f") mlabc(`c1') mlabpos(9) mlabs(*.7)
    local lab1 mlabel(m`q') mlabf("%5,1f") mlabc(`c2') mlabpos(2) mlabs(*.7)
    local lab2 mlabel(m`q') mlabf("%5,1f") mlabc(`c3') mlabpos(3) mlabs(*.7)
    twoway ///
        (rcap  `cap_up' `cap_low' x_0 if type == 1, color(`c1')  )              ///
        (rcap  `cap_up' `cap_low' x_1 if type == 2, color(`c2')  )              ///
        (rcap  `cap_up' `cap_low' x_2 if type == 4, color(`c3')  )              ///
        (scatter  m`q' x_0 if type == 1, m(O) mlc(`c1') mfc(`c1'%50) `lab0')    ///
        (scatter  m`q' x_1 if type == 2, m(S) mlc(`c2') mfc(`c2'%50) `lab1')    ///
        (scatter  m`q' x_2 if type == 4, m(D) mlc(`c3') mfc(`c3'%50) `lab2')    ///
        ,                                                                       ///
        xtitle("")                                                              ///
        ylabel(0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9"      ///
            10 "10", labsize(*.9) )                                             ///  
        ytitle("`ytitre'", size(*.9) margin(0 4  0 0))                          ///
        xlabel( 1 `" "{bf:PCF}" "(N=`=n`q'[1]')" "'                             ///
                2 `" "{bf:LFI}" "(N=`=n`q'[2]')" "'                             /// 
                3 `" "{bf:PS}"  "(N=`=n`q'[3]')" "'                             ///
                4 `" "{bf:EELV}" "(N=`=n`q'[4]')" "'                            ///
                5 `" "{bf:Renaiss.}" "(N=`=n`q'[5]')" "'                        ///
                6 `" "{bf:LR}" "(N=`=n`q'[6]')" "'                              ///
                7 `" "{bf:RN}" "(N=`=n`q'[7]')" "'                              ///
                8 `" "{bf:Rec.}" "(N=`=n`q'[8]')" "', labsize(*.9) )            ///
         `leg'                                                                  ///
        text(-0.5  `labpos' "{bf:`tlow'}", orient(vertical) place(12)           ///
            size(*`labsize'))                                                   ///
        text(10.5 `labpos' "{bf:`tup'}" orient(vertical) place(6)               ///
            size(*`labsize'))                                                   ///
        graphregion(m(2 9 2 2 ))  name(q`q', replace) `options'
end 


/******************************************************************************/
/*                                  Global color                              */
/******************************************************************************/

global c1 black
global c2 gs10
global c3 gs7  

/******************************************************************************/
/*                                 Data preparation                           */  
/******************************************************************************/

use raw_data, clear

/* Mean count and Standart déviation by type of respondant and party */
collapse                                                                        ///
    (mean) m1=Q1 m2=Q2 m3=Q3 m4=Q4  m5=Q5 m6=Q6 m7=Q7 m8=Q8 m9=Q9 m10=Q10       ///
    (sd)   s1=Q1 s2=Q2 s3=Q3 s4=Q4  s5=Q5 s6=Q6 s7=Q7 s8=Q8 s9=Q9 s10=Q10       ///
    (count) n1=Q1 n2=Q2 n3=Q3 n4=Q4 n5=Q5 n6=Q6 n7=Q7 n8=Q8 n9=Q9 n10=Q10,      ///
    by(party type)
    
gen x_0 = party - 0.15     // Experts
gen x_1 = party           // ChatGPT
gen x_2 = party + 0.15     // MistralAI

/******************************************************************************/
/*                                    Q1                                      */
/*  Comment décririez-vous la position générale des partis suivant sur        */
/*                        l'échelle gauche-droite ?                           */
/******************************************************************************/

mygraph3_en, q(1) title("A. Left-right divide") plotregion(m(6 4 2 4)) ///
    tl("← Extreme left") tu("Extreme right →")  labp(0.25) labs(0.6)   
    
/******************************************************************************/
/*                                    Q2                                      */
/*  Comment décririez-vous la position générale des partis suivants           */
/*                   sur l'intégration Européenne ?                           */
/******************************************************************************/
mygraph3_en, q(2) title("B. European integration") plotregion(m(6 1 2 0)) ///
    tl("← Strongly opposed") tu("Strongly favorable →")  labp(-0.25) labs(0.7)    

/******************************************************************************/
/*                                    Q5                                      */
/*  Comment décririez-vous la position des partis suivants en ce qui concerne */
/*                              l'immigration ?                               */
/******************************************************************************/
mygraph3_en, q(5) title("C. Immigration") plotregion(m(6 1 2 0)) ///
    tl("← Strongly opposed") tu("Strongly favorable →")  labp(-0.25) labs(0.7)


/******************************************************************************/    
/******************************************************************************/
/*                               Figure 1                                     */
/******************************************************************************/
/******************************************************************************/      
grc1leg2 q2 q5, row(1) name(tt, replace)  ycommon      
grc1leg2 q1 tt , col(1) ysize(4.5) xsize(6) altshrink imargin(0 0 0 0)          ///
    iscale(*2) graphregion(m(2 1 0 0))  




/******************************************************************************/    
/******************************************************************************/
/*        Figure 2 :free-market, asylum, and rural vs. urban interests        */
/******************************************************************************/
/******************************************************************************/   

mygraph3_en , q(8) title("A. Free-market") nolegend  plotregion(m(6 4 2 4))     ///
    tl("← Strongly favorable") tu("Strongly opposed →") labp(0.25) labs(0.6)
mygraph3_en , q(9) title("B. Asylum")   plotregion(m(6 1 2 0))                  ///
    tl("← Strongly favorable") tu("Strongly opposed →") labp(-0.25) labs(0.7)
mygraph3_en , q(10) title("C. Rural vs. urban interests")  plotregion(m(6 1 2 0)) ///
    tl("← Strongly favorable") tu("VStrongly opposed →") labp(-0.25) labs(0.7) 
grc1leg2 q9 q10 , row(1)  name(tt, replace)
graph combine q8 tt, col(1) ysize(4.5) xsize(6) altshrink imargin(0 0 0 0)      ///
    iscale(*2) graphregion(m(2 1 0 0))



/******************************************************************************/    
/******************************************************************************/
/*                Figure 3: Within-party division & Issue-blurring            */
/******************************************************************************/
/******************************************************************************/    
mygraph3_en , q(3) title("A. Within-party division") nolegend  plotregion(m(6 1 2 0)) ///
    tl("← Perfectly united") tu("Extremely disunited →") labp(-0.25) labs(0.7)
mygraph3_en , q(4) title("B. Issue-blurring")  nolegend plotregion(m(6 1 2 0))  ///
    tl("← Don't mask at all") tu("Mask a lot →") labp(-0.25) labs(0.7)
grc1leg2 q3 q4, row(1)  name(tt, replace) title("European integration")

mygraph3_en , q(6) title("C. Within-party division")  plotregion(m(6 1 2 0)) ///
    tl("← Perfectly united") tu("Extremely disunited →") labp(-0.25) labs(0.7)       
mygraph3_en , q(7) title("D. Issue-blurring")  plotregion(m(6 1 2 0)) ///
    tl("← Don't mask at all") tu("Mask a lot →") labp(-0.25) labs(0.7) 
grc1leg2 q6 q7, row(1)  name(ttt, replace) title("Immigration")

grc1leg2 tt ttt, col(1) leg(ttt) ysize(4.5) xsize(6) altshrink imargin(0 0 0 0) ///
    iscale(*2) graphregion(m(2 1 0 0))


/******************************************************************************/    
/******************************************************************************/
/*                  Figure 4: Mean Absolute Deviation                         */
/******************************************************************************/
/******************************************************************************/    

/* By question */
frame copy default tt, replace
frame change tt
keep party type m*
drop if type > 2

reshape wide m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, i(party) j(type)

forvalues i = 1/10 {
    gen Q`i' = abs(m`i'1-m`i'2) 
}

collapse (mean) Q* 
gen id = 1
reshape long Q, i(id) j(q) 

sort Q
replace id = -_n


twoway ///
    (bar   Q id, hor color($c2) barwidth(0.5) mlabel(Q) mlabc(black)            ///
            mlabf("%2.1f")  mlabp(2)  mlabsize(*1.2) )                          ///
    /*(rcap  lbar ubar id, hor color($c1)  )*/,                                 ///
    yscale(lcol(none)) ytitle("")                                               ///
    ylabel(                                                                     ///
        -1 "EU integration"                                                     ///
        -2 "Immigration"                                                        ///
        -3 "Left-right divide"                                                  ///
        -4 `" "Immigration" "Within-party division" "'                          ///
        -5 "Free-market"                                                        ///
        -6 `" "EU integration" "Within-party division" "'                       ///
        -7 `" "EU integration" "Issue-blurring" "'                              ///
        -8 "Rural/Urban"                                                        ///
        -9 `" "Immigration" "Issue-blurring" "'                                 ///
       -10 "Asylum"                                                             ///
    , nogrid labsize(*0.9) noticks  )                                           ///
    xtitle("")                                                                  ///
    xlabel(0(0.5)2, nogrid  labsize(*1))                                        ///
    title("By issue")                                                           ///
    legend(off) ysize(4.5) xsize(6) name(byq, replace)    
frame change default

/* by Party */ 
frame copy default tt, replace
frame change tt
keep party type m*
drop if type > 2

reshape wide m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, i(party) j(type)
reshape long m@1 m@2, i(party) j(q) 

gen P = abs(m1 - m2)
collapse (mean) P , by(party)
sort P
gen id = - _n

twoway ///
    (bar   P id, hor color($c2) barwidth(0.5) mlabel(P) mlabc(black)            ///
            mlabf("%2.1f")  mlabp(2) mlabsize(*1.2) )                           ///
    /*(rcap  lbar ubar id, hor color($c1)  )*/,                                 ///
    yscale(lcol(none)) ytitle("")                                               ///
    ylabel(                                                                     ///
        -1 "PCF"                                                                ///
        -2 "Rec. !"                                                             ///
        -3 "EELV"                                                               ///
        -4 "RN"                                                                 ///
        -5 "PS"                                                                 ///
        -6 "LR"                                                                 ///
        -7 "Renaiss."                                                           ///
        -8 "LFI"                                                                ///
    , nogrid labsize(*1.2) noticks  )                                           ///
    xtitle("")                                                                  ///
    xlabel(0(0.5)2, nogrid  labsize(*1))                                        ///
    title("By party")                                                           ///
    legend(off) ysize(4.5) xsize(6) name(byp, replace)    

    
frame change default

graph combine byp byq, row(1) ysize(3) xsize(6)